Technical Q&AHW 08 - Implementing read-modify-write on PCI (15-July-95)Q We are converting our Nubus card to a PCI card, and we need to know how to implement read-modify-write to lock the PCI target device. A Designing PCI Cards and Drivers, which is on the PCI Driver Development Kit (DDK), explains this as follows: Atomic Memory Operations Boolean CompareAndSwap(long oldValue, long newValue, long *Value); SInt32 IncrementAtomic( SInt32 *value ); SInt32 DecrementAtomic( SInt32 *value ); SInt32 AddAtomic( SInt32 amount, SInt32 *value ); UInt32 BitAndAtomic( UInt32 mask, UInt32 *value ); UInt32 BitOrAtomic( UInt32 mask, UInt32 *value ); UInt32 BitXorAtomic( UInt32 mask, UInt32 *value ); SInt8 IncrementAtomic8( SInt8 *value ); SInt8 DecrementAtomic8( SInt8 *value ); SInt8 AddAtomic8( SInt32 amount, SInt8 *value ); UInt8 BitAndAtomic8( UInt32 mask, UInt8 *value ); UInt8 BitOrAtomic8( UInt32 mask, UInt8 *value ); UInt8 BitXorAtomic8( UInt32 mask, UInt8 *value ); SInt16 IncrementAtomic16( SInt16 *value ); SInt16 DecrementAtomic16( SInt16 *value ); SInt16 AddAtomic16( SInt32 amount, SInt16 *value ); UInt16 BitAndAtomic16( UInt32 mask, UInt16 *value ); UInt16 BitOrAtomic16( UInt32 mask, UInt16 *value ); UInt16 BitXorAtomic16( UInt32 mask, UInt16 *value ); The atomic routines perform various operations on the memory address specified by value: * IncrementAtomic increments the value by one and DecrementAtomic decrements it
by one. These functions return the value as it was before the change. These routines take logical address pointers and ensure that the operations are atomic with respect to all devices (for example, other processors, DMA engines) that participate in the coherency architecture of the Macintosh system. TestAndSet (UInt32 theBit UInt8 *theAddress); TestAndClear (UInt32 theBit UInt8 *theAddress); theBit The bit number in the range 0 through 7. theAddress The address of the byte in which the bit is located. TestAndSet and TestAndClear set and clear a single bit in a byte at a specified address. Technical Q&A Previous Question | Contents | Next Question |